package Java_teat_3;

public class Conpany {
    String name;
    String addess;
    String tel;
    String jinyinfanw;
    public Conpany(String n,String a,String t,String j){
        this.name=n;
        this.addess=a;
        this.tel=t;
        this.jinyinfanw=j;
    }
    Yuangong []yg=new Yuangong[100];
    //招聘员工
    public boolean addName(Yuangong yuangong){
        for (int i=0;i<yg.length;i++){
            if (yg[i]!=null&&(yuangong.name).equals(yg[i].name)){
                System.out.println("名字重复，请重新输入");
                return false;
            }else {
                if (yg[i]==null){
                    yg[i]=yuangong;
                    return true;
                }
            }
        }
        return false;
    }
    //输出员工信息
    public void showXx(){
     if (yg[0]==null){
         System.out.println("没有员工");
     }
     for (int i=0;i<yg.length;i++){
         if (yg[i]!=null){
             System.out.println("姓名"+yg[i].name);
             System.out.println("年龄"+yg[i].age );
             System.out.println("性别"+yg[i].sex);
             System.out.println("职位"+yg[i].zhiwu);
             System.out.println("薪水"+yg[i].xinshui);
         }
     }
    }
    //辞退员工
    public boolean expel(String name){
        for (int i=0;i<yg.length;i++){
            if (yg[i]!=null&&name.equals(yg[i].name)){
                for (int j=0;j<yg.length-1;j++){
                    yg[j]=yg[j+1];
                    return true;
                }
            }
            yg[yg.length-1]=null;
        }
        return false;
    }
    //统计公司人数
    public int renshu(){
        int count=0;//记录人数
        for (int i=0;i<yg.length;i++){
            if (yg[i]!=null){
                count++;
            }else{
                break;
            }
        }return count;
    }
   //查找薪水最高的员工
   public Yuangong  findTopSalary(){
        int index=0;
        double max=0;
        for (int i=0;i<yg.length;i++){
            if (yg[i]!=null&&yg[i].xinshui>max){
                max=yg[i].xinshui;
                index=i;
            }
        }return yg[index];
   }
   //薪水从高到低排序
    public void sortBySalDesc(){
        for (int i=0;i<yg.length-1;i++){
            for (int j=i;j<yg.length-i-1;j++){
                if (yg[j]!=null&&yg[j].xinshui<yg[j+1].xinshui){
                    double temp=yg[j].xinshui;
                    yg[j].xinshui=yg[j+1].xinshui;
                    yg[j+1].xinshui=temp;
                }
            }
        }
        for (int i=0;i<yg.length;i++){
            if (yg[i]!=null)
                System.out.println(yg[i].xinshui);
        }
    }
}
